package Operation;

import Book.Book;

import Book.BookList;

import java.util.Scanner;

public class AddOperation implements IOPeration{
    public void work(BookList bookList){
        System.out.println("新增图书..");
        System.out.println("请输入你要添加的书名:");
        Scanner scanner = new Scanner(System.in);

        String name = scanner.nextLine();

        int currentsize = bookList.getUsedsize();
        for(int i = 0; i < currentsize; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)){
                System.out.println("这本书已经存在");
                System.out.println(book);
                return;
            }
        }
        //查到最后
        System.out.println("请输入新增书的作者名");
        String author = scanner.nextLine();

        System.out.println("请输入新增书的价格:");
        int price = scanner.nextInt();

        scanner.nextLine();

        System.out.println("请输入新增书的类型:");
        String type = scanner.nextLine();

        Book book = new Book(name,author,price,type);

        bookList.setBooks(currentsize, book);

        bookList.setUsedsize(currentsize + 1);
    }
}
